package clientUtilGUI;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class ComboBoxRenderer extends JLabel implements ListCellRenderer {
	//	private Font uhOhFont;
	ImageIcon[] images;
	public ComboBoxRenderer(ImageIcon[] _images) {
		images = _images;
		setOpaque(true);
		setHorizontalAlignment(LEADING);
		setVerticalAlignment(CENTER);
	}

	/*
	* This method finds the image and text corresponding
	* to the selected value and returns the label, set up
	* to display the text and image.
	*/
	public Component getListCellRendererComponent(
				                    JList list,
				                    Object value,
				                    int index,
				                    boolean isSelected,
				                    boolean cellHasFocus) {
		//Get the selected index. (The index param isn't
		//always valid, so just use the value.)
		int selectedIndex = ((Integer)value).intValue();
		
		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}
		
		//Set the icon and text.  If icon was null, say so.
		ImageIcon icon = images[selectedIndex];
//		String pet = locationStrings[selectedIndex];
		setIcon(icon);
//		if (icon != null) {
//			setText(pet);
//			setFont(list.getFont());
//		} else {
//			setUhOhText(pet + " (no image available)", list.getFont());
//		}

		return this;
	}

//	//Set the font and text when no image was found.
//	protected void setUhOhText(String uhOhText, Font normalFont) {
//		if (uhOhFont == null) { //lazily create this font
//			uhOhFont = normalFont.deriveFont(Font.ITALIC);
//		}
//			setFont(uhOhFont);
//			setText(uhOhText);
//	}
}